home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axgrid / clspnttl.cls < prev    next >
Encoding:
Visual Basic class definition  |  1998-06-04  |  50.1 KB  |  1,190 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "PaintEffects"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Attribute VB_Description = "Provides methods for painting transparent and disabled looking images."
  11. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  12. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  13. '*****************************************************************
  14. '
  15. '   POPUPCOMMAND CONTROL
  16. '
  17. '   This code and control is absolutely freeware!
  18. '
  19. '   You have a royalty-free right to use, modify, reproduce and distribute
  20. '   the source code and control (and/or any modified version) in any way
  21. '   you find useful, provided that you agree that the authors have no warranty,
  22. '   obligations or liability for any code distributed in this project group.
  23. '
  24. ' Copyright ⌐ 1998 by Geoff Glaze
  25. '
  26. '   (Some parts borrowed from Microsoft)
  27. '
  28. '*****************************************************************
  29.  
  30.  
  31. '-------------------------------------------------------------------------
  32. 'This class provides methods needed for painting masked bitmaps and
  33. 'disabled or embossed bitmaps and icons
  34. '-------------------------------------------------------------------------
  35.  
  36. Option Explicit
  37.  
  38. Private m_hpalHalftone As Long  'Halftone created for default palette use
  39.  
  40. '-------------------------------------------------------------------------
  41. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  42. '           input bitmap.
  43. 'In:
  44. '   [hdcDest]
  45. '           Device context to paint the picture on
  46. '   [xDest]
  47. '           X coordinate of the upper left corner of the area that the
  48. '           picture is to be painted on. (in pixels)
  49. '   [yDest]
  50. '           Y coordinate of the upper left corner of the area that the
  51. '           picture is to be painted on. (in pixels)
  52. '   [Width]
  53. '           Width of picture area to paint in pixels.  Note: If this value
  54. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  55. '           instead of the pictures' width in pixels), this procedure will
  56. '           attempt to create bitmaps that require outrageous
  57. '           amounts of memory.
  58. '   [Height]
  59. '           Height of picture area to paint in pixels.  Note: If this
  60. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  61. '           twips instead of the pictures' height in pixels), this
  62. '           procedure will attempt to create bitmaps that require
  63. '           outrageous amounts of memory.
  64. '   [picSource]
  65. '           Standard Picture object to be used as the image source
  66. '   [xSrc]
  67. '           X coordinate of the upper left corner of the area in the picture
  68. '           to use as the source. (in pixels)
  69. '           Ignored if picSource is an Icon.
  70. '   [ySrc]
  71. '           Y coordinate of the upper left corner of the area in the picture
  72. '           to use as the source. (in pixels)
  73. '           Ignored if picSource is an Icon.
  74. '   [clrMask]
  75. '           Color of pixels to be masked out
  76. '   [clrHighlight]
  77. '           Color to be used as outline highlight
  78. '   [clrShadow]
  79. '           Color to be used as outline shadow
  80. '   [hPal]
  81. '           Handle of palette to select into the memory DC's used to create
  82. '           the painting effect.
  83. '           If not provided, a HalfTone palette is used.
  84. '-------------------------------------------------------------------------
  85. Public Sub PaintDisabledStdPic(ByVal hdcDest As Long, _
  86.                                 ByVal xDest As Long, _
  87.                                 ByVal yDest As Long, _
  88.                                 ByVal Width As Long, _
  89.                                 ByVal Height As Long, _
  90.                                 ByVal picSource As StdPicture, _
  91.                                 ByVal xSrc As Long, _
  92.                                 ByVal ySrc As Long, _
  93.                                 Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  94.                                 Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  95.                                 Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  96.                                 Optional ByVal hPal As Long = 0)
  97.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  98.     Dim hbmMemSrcOld As Long
  99.     Dim hbmMemSrc As Long
  100.     Dim udtRect As RECT
  101.     Dim hbrMask As Long
  102.     Dim lMaskColor As Long
  103.     Dim hdcScreen As Long
  104.     Dim hPalOld As Long
  105.     
  106.     'Verify that the passed picture is not nothing
  107.     If picSource Is Nothing Then GoTo PaintDisabledDC_InvalidParam
  108.     Select Case picSource.Type
  109.         Case vbPicTypeBitmap
  110.             'Select passed picture into an HDC
  111.             hdcScreen = GetDC(0&)
  112.             'Validate palette
  113.             If hPal = 0 Then
  114.                 hPal = m_hpalHalftone
  115.             End If
  116.             hdcSrc = CreateCompatibleDC(hdcScreen)
  117.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  118.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  119.             RealizePalette hdcSrc
  120.             
  121.             'Draw the bitmap
  122.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, clrMask, clrHighlight, clrShadow, hPal
  123.             
  124.             SelectObject hdcSrc, hbmMemSrcOld
  125.             SelectPalette hdcSrc, hPalOld, True
  126.             RealizePalette hdcSrc
  127.             DeleteDC hdcSrc
  128.             ReleaseDC 0&, hdcScreen
  129.         Case vbPicTypeIcon
  130.             'Create a bitmap and select it into a DC
  131.             hdcScreen = GetDC(0&)
  132.             'Validate palette
  133.             If hPal = 0 Then
  134.                 hPal = m_hpalHalftone
  135.             End If
  136.             hdcSrc = CreateCompatibleDC(hdcScreen)
  137.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  138.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  139.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  140.             RealizePalette hdcSrc
  141.             'Draw Icon onto DC
  142.             udtRect.Bottom = Height
  143.             udtRect.Right = Width
  144.             OleTranslateColor clrMask, 0&, lMaskColor
  145.             SetBkColor hdcSrc, lMaskColor
  146.             hbrMask = CreateSolidBrush(lMaskColor)
  147.             FillRect hdcSrc, udtRect, hbrMask
  148.             DeleteObject hbrMask
  149.             DrawIcon hdcSrc, 0, 0, picSource.handle
  150.             'Draw Disabled image
  151.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0&, 0&, clrMask, clrHighlight, clrShadow, hPal
  152.             'Clean up
  153.             SelectPalette hdcSrc, hPalOld, True
  154.             RealizePalette hdcSrc
  155.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  156.             DeleteDC hdcSrc
  157.             ReleaseDC 0&, hdcScreen
  158.         Case Else
  159.             GoTo PaintDisabledDC_InvalidParam
  160.     End Select
  161.     Exit Sub
  162. PaintDisabledDC_InvalidParam:
  163.     Error.Raise giINVALID_PICTURE
  164.     Exit Sub
  165. End Sub
  166.  
  167. '-------------------------------------------------------------------------
  168. 'Purpose:   Creates a disabled-appearing (grayed) bitmap, given any format of
  169. '           input bitmap.
  170. 'In:
  171. '   [hdcDest]
  172. '           Device context to paint the picture on
  173. '   [xDest]
  174. '           X coordinate of the upper left corner of the area that the
  175. '           picture is to be painted on. (in pixels)
  176. '   [yDest]
  177. '           Y coordinate of the upper left corner of the area that the
  178. '           picture is to be painted on. (in pixels)
  179. '   [Width]
  180. '           Width of picture area to paint in pixels.  Note: If this value
  181. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  182. '           instead of the pictures' width in pixels), this procedure will
  183. '           attempt to create bitmaps that require outrageous
  184. '           amounts of memory.
  185. '   [Height]
  186. '           Height of picture area to paint in pixels.  Note: If this
  187. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  188. '           twips instead of the pictures' height in pixels), this
  189. '           procedure will attempt to create bitmaps that require
  190. '           outrageous amounts of memory.
  191. '   [hdcSrc]
  192. '           Device context that contains the source picture
  193. '   [xSrc]
  194. '           X coordinate of the upper left corner of the area in the picture
  195. '           to use as the source. (in pixels)
  196. '   [ySrc]
  197. '           Y coordinate of the upper left corner of the area in the picture
  198. '           to use as the source. (in pixels)
  199. '   [clrMask]
  200. '           Color of pixels to be masked out
  201. '   [clrHighlight]
  202. '           Color to be used as outline highlight
  203. '   [clrShadow]
  204. '           Color to be used as outline shadow
  205. '   [hPal]
  206. '           Handle of palette to select into the memory DC's used to create
  207. '           the painting effect.
  208. '           If not provided, a HalfTone palette is used.
  209. '-------------------------------------------------------------------------
  210. Public Sub PaintDisabledDC(ByVal hdcDest As Long, _
  211.                                 ByVal xDest As Long, _
  212.                                 ByVal yDest As Long, _
  213.                                 ByVal Width As Long, _
  214.                                 ByVal Height As Long, _
  215.                                 ByVal hdcSrc As Long, _
  216.                                 ByVal xSrc As Long, _
  217.                                 ByVal ySrc As Long, _
  218.                                 Optional ByVal clrMask As OLE_COLOR = vbWhite, _
  219.                                 Optional ByVal clrHighlight As OLE_COLOR = vb3DHighlight, _
  220.                                 Optional ByVal clrShadow As OLE_COLOR = vb3DShadow, _
  221.                                 Optional ByVal hPal As Long = 0)
  222.     Dim hdcScreen As Long
  223.     Dim hbmMonoSection As Long
  224.     Dim hbmMonoSectionSav As Long
  225.     Dim hdcMonoSection As Long
  226.     Dim hdcColor As Long
  227.     Dim hdcDisabled As Long
  228.     Dim hbmDisabledSav As Long
  229.     Dim lpbi As BITMAPINFO
  230.     Dim hbmMono As Long
  231.     Dim hdcMono As Long
  232.     Dim hbmMonoSav As Long
  233.     Dim lMaskColor As Long
  234.     Dim lMaskColorCompare As Long
  235.     Dim hdcMaskedSource As Long
  236.     Dim hbmMasked As Long
  237.     Dim hbmMaskedOld As Long
  238.     Dim hpalMaskedOld As Long
  239.     Dim hpalDisabledOld As Long
  240.     Dim hpalMonoOld As Long
  241.     Dim rgbBlack As RGBQUAD
  242.     Dim rgbWhite As RGBQUAD
  243.     Dim dwSys3dShadow As Long
  244.     Dim dwSys3dHighlight As Long
  245.     Dim pvBits As Long
  246.     Dim rgbnew(1) As RGBQUAD
  247.     Dim hbmDisabled As Long
  248.     Dim lMonoBkGrnd As Long
  249.     Dim lMonoBkGrndChoices(2) As Long
  250.     Dim lIndex As Long  'For ... Next index
  251.     Dim hbrWhite As Long
  252.     Dim udtRect As RECT
  253.     
  254.     'TODO: handle pictures with dark masks
  255.     If hPal = 0 Then
  256.         hPal = m_hpalHalftone
  257.     End If
  258.   ' Define some colors
  259.     OleTranslateColor clrShadow, hPal, dwSys3dShadow
  260.     OleTranslateColor clrHighlight, hPal, dwSys3dHighlight
  261.     
  262.     hdcScreen = GetDC(0&)
  263.     With rgbBlack
  264.         .rgbBlue = 0
  265.         .rgbGreen = 0
  266.         .rgbRed = 0
  267.         .rgbReserved = 0
  268.     End With
  269.     With rgbWhite
  270.         .rgbBlue = 255
  271.         .rgbGreen = 255
  272.         .rgbRed = 255
  273.         .rgbReserved = 255
  274.     End With
  275.  
  276.     ' The first step is to create a monochrome bitmap with two colors:
  277.     ' white where colors in the original are light, and black
  278.     ' where the original is dark.  We can't simply bitblt to a bitmap.
  279.     ' Instead, we create a monochrome (bichrome?) DIB section and bitblt
  280.     ' to that.  Windows will do the conversion automatically based on the
  281.     ' DIB section's palette.  (I.e. using a DIB section, Windows knows how
  282.     ' to map "light" colors and "dark" colors to white/black, respectively.
  283.     With lpbi.bmiHeader
  284.         .biSize = LenB(lpbi.bmiHeader)
  285.         .biWidth = Width
  286.         .biHeight = -Height
  287.         .biPlanes = 1
  288.         .biBitCount = 1         ' monochrome
  289.         .biCompression = BI_RGB
  290.         .biSizeImage = 0
  291.         .biXPelsPerMeter = 0
  292.         .biYPelsPerMeter = 0
  293.         .biClrUsed = 0          ' max colors used (2^1 = 2)
  294.         .biClrImportant = 0     ' all (both :-]) colors are important
  295.     End With
  296.     With lpbi
  297.         .bmiColors(0) = rgbBlack
  298.         .bmiColors(1) = rgbWhite
  299.     End With
  300.  
  301.     hbmMonoSection = CreateDIBSection(hdcScreen, lpbi, DIB_RGB_COLORS, pvBits, 0&, 0)
  302.     
  303.     hdcMonoSection = CreateCompatibleDC(hdcScreen)
  304.     hbmMonoSectionSav = SelectObject(hdcMonoSection, hbmMonoSection)
  305.     
  306.     'Bitblt to the Monochrome DIB section
  307.     'If a mask color is provided, create a new bitmap and copy the source
  308.     'to it transparently.  If we don't do this, a dark mask color will be
  309.     'turned into the outline part of the monochrome DIB section
  310.     'Convert mask color and white before comparing
  311.     'because the Mask color might be a system color that would be evaluated
  312.     'to white.
  313.     OleTranslateColor vbWhite, hPal, lMaskColorCompare
  314.     OleTranslateColor clrMask, hPal, lMaskColor
  315.     If lMaskColor = lMaskColorCompare Then
  316.         BitBlt hdcMonoSection, 0, 0, Width, Height, hdcSrc, xSrc, ySrc, vbSrcCopy
  317.     Else
  318.         hbmMasked = CreateCompatibleBitmap(hdcScreen, Width, Height)
  319.         hdcMaskedSource = CreateCompatibleDC(hdcScreen)
  320.         hbmMaskedOld = SelectObject(hdcMaskedSource, hbmMasked)
  321.         hpalMaskedOld = SelectPalette(hdcMaskedSource, hPal, True)
  322.         RealizePalette hdcMaskedSource
  323.         'Fill the bitmap with white
  324.         With udtRect
  325.             .Left = 0
  326.             .Top = 0
  327.             .Right = Width
  328.             .Bottom = Height
  329.         End With
  330.         hbrWhite = CreateSolidBrush(vbWhite)
  331.         FillRect hdcMaskedSource, udtRect, hbrWhite
  332.         DeleteObject hbrWhite
  333.         'Do the transparent paint
  334.         PaintTransparentDC hdcMaskedSource, 0, 0, Width, Height, hdcSrc, xSrc, ySrc, lMaskColor, hPal
  335.         'BitBlt to the Mono DIB section.  The mask color has been turned to white.
  336.         BitBlt hdcMonoSection, 0, 0, Width, Height, hdcMaskedSource, 0, 0, vbSrcCopy
  337.         'Clean up
  338.         SelectPalette hdcMaskedSource, hpalMaskedOld, True
  339.         RealizePalette hdcMaskedSource
  340.         DeleteObject SelectObject(hdcMaskedSource, hbmMaskedOld)
  341.         DeleteDC hdcMaskedSource
  342.     End If
  343.       
  344.     ' Okay, we've got our B&W DIB section.
  345.     ' Now that we have our monochrome bitmap, the final appearance that we
  346.     ' want is this:  First, think of the black portion of the monochrome
  347.     ' bitmap as our new version of the original bitmap.  We want to have a dark
  348.     ' gray version of this with a light version underneath it, shifted down and
  349.     ' to the right.  The light acts as a highlight, and it looks like the original
  350.     ' image is a gray inset.
  351.     
  352.     ' First, create a copy of the destination.  Draw the light gray transparently,
  353.     ' and then draw the dark gray transparently
  354.     
  355.     hbmDisabled = CreateCompatibleBitmap(hdcScreen, Width, Height)
  356.     
  357.     hdcDisabled = CreateCompatibleDC(hdcScreen)
  358.     hbmDisabledSav = SelectObject(hdcDisabled, hbmDisabled)
  359.     hpalDisabledOld = SelectPalette(hdcDisabled, hPal, True)
  360.     RealizePalette hdcDisabled
  361.     'We used to fill the background with gray, instead copy the
  362.     'destination to memory DC.  This will allow a disabled image
  363.     'to be drawn over a background image.
  364.     BitBlt hdcDisabled, 0, 0, Width, Height, hdcDest, xDest, yDest, vbSrcCopy
  365.     
  366.     'When painting the monochrome bitmaps transparently onto the background
  367.     'we need a background color that is not the light color of the dark color
  368.     'Provide three choices to ensure a unique color is picked.
  369.     OleTranslateColor vbBlack, hPal, lMonoBkGrndChoices(0)
  370.     OleTranslateColor vbRed, hPal, lMonoBkGrndChoices(1)
  371.     OleTranslateColor vbBlue, hPal, lMonoBkGrndChoices(2)
  372.     
  373.     'Pick a background color choice that doesn't match
  374.     'the shadow or highlight color
  375.     For lIndex = 0 To 2
  376.         If lMonoBkGrndChoices(lIndex) <> dwSys3dHighlight And _
  377.                 lMonoBkGrndChoices(lIndex) <> dwSys3dShadow Then
  378.             'This color can be used for a mask
  379.             lMonoBkGrnd = lMonoBkGrndChoices(lIndex)
  380.             Exit For
  381.         End If
  382.     Next
  383.  
  384.     ' Now paint a the light color shifted and transparent over the background
  385.     ' It is not necessary to change the DIB section's color table
  386.     ' to equal the highlight color and mask color.  In fact, setting
  387.     ' the color table to anything besides black and white causes unpredictable
  388.     ' results (seen in win95 with IE4, using 256 colors).
  389.     ' Setting the Back and Text colors of the Monochrome bitmap, ensure
  390.     ' that the desired colors are produced.
  391.     With rgbnew(0)
  392.         .rgbRed = (vbWhite \ 2 ^ 16) And &HFF
  393.         .rgbGreen = (vbWhite \ 2 ^ 8) And &HFF
  394.         .rgbBlue = vbWhite And &HFF
  395.     End With
  396.     With rgbnew(1)
  397.         .rgbRed = (vbBlack \ 2 ^ 16) And &HFF
  398.         .rgbGreen = (vbBlack \ 2 ^ 8) And &HFF
  399.         .rgbBlue = vbBlack And &HFF
  400.     End With
  401.         
  402.     SetDIBColorTable hdcMonoSection, 0, 2, rgbnew(0)
  403.     
  404.     '...We can't pass a DIBSection to PaintTransparentDC(), so we need to
  405.     ' make a copy of our mono DIBSection.  Notice that we only need a monochrome
  406.     ' bitmap, but we must set its back/fore colors to the monochrome colors we
  407.     ' want (light gray and black), and PaintTransparentDC() will honor them.
  408.     hbmMono = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
  409.     hdcMono = CreateCompatibleDC(hdcScreen)
  410.     hbmMonoSav = SelectObject(hdcMono, hbmMono)
  411.     SetMapMode hdcMono, GetMapMode(hdcSrc)
  412.     SetBkColor hdcMono, dwSys3dHighlight
  413.     SetTextColor hdcMono, lMonoBkGrnd
  414.     hpalMonoOld = SelectPalette(hdcMono, hPal, True)
  415.     RealizePalette hdcMono
  416.     BitBlt hdcMono, 0, 0, Width, Height, hdcMonoSection, 0, 0, vbSrcCopy
  417.  
  418.     '...We can go ahead and call PaintTransparentDC with our monochrome
  419.     ' copy
  420.     ' Draw this transparently over the disabled bitmap
  421.     '...Don't forget to shift right and left....
  422.     PaintTransparentDC hdcDisabled, 1, 1, Width, Height, hdcMono, 0, 0, lMonoBkGrnd, hPal
  423.     
  424.     ' Now draw a transparent copy, using dark gray where the monochrome had
  425.     ' black, and transparent elsewhere.  We'll use a transparent color of black.
  426.  
  427.     '...We can't pass a DIBSection to PaintTransparentDC(), so we need to
  428.     ' make a copy of our mono DIBSection.  Notice that we only need a monochrome
  429.     ' bitmap, but we must set its back/fore colors to the monochrome colors we
  430.     ' want (dark gray and black), and PaintTransparentDC() will honor them.
  431.     ' Use hbmMono and hdcMono; already created for first color
  432.     SetBkColor hdcMono, dwSys3dShadow
  433.     SetTextColor hdcMono, lMonoBkGrnd
  434.     BitBlt hdcMono, 0, 0, Width, Height, hdcMonoSection, 0, 0, vbSrcCopy
  435.  
  436.     '...We can go ahead and call PaintTransparentDC with our monochrome
  437.     ' copy
  438.     ' Draw this transparently over the disabled bitmap
  439.     PaintTransparentDC hdcDisabled, 0, 0, Width, Height, hdcMono, 0, 0, lMonoBkGrnd, hPal
  440.     BitBlt hdcDest, xDest, yDest, Width, Height, hdcDisabled, 0, 0, vbSrcCopy
  441.     ' Okay, we're done!
  442.     SelectPalette hdcDisabled, hpalDisabledOld, True
  443.     RealizePalette hdcDisabled
  444.     DeleteObject SelectObject(hdcMonoSection, hbmMonoSectionSav)
  445.     DeleteDC hdcMonoSection
  446.     DeleteObject SelectObject(hdcDisabled, hbmDisabledSav)
  447.     DeleteDC hdcDisabled
  448.     DeleteObject SelectObject(hdcMono, hbmMonoSav)
  449.     SelectPalette hdcMono, hpalMonoOld, True
  450.     RealizePalette hdcMono
  451.     DeleteDC hdcMono
  452.     ReleaseDC 0&, hdcScreen
  453. End Sub
  454.  
  455. '-------------------------------------------------------------------------
  456. 'Purpose:   Draws a transparent bitmap to a DC.  The pixels of the passed
  457. '           bitmap that match the passed mask color will not be painted
  458. '           to the destination DC
  459. 'In:
  460. '   [hdcDest]
  461. '           Device context to paint the picture on
  462. '   [xDest]
  463. '           X coordinate of the upper left corner of the area that the
  464. '           picture is to be painted on. (in pixels)
  465. '   [yDest]
  466. '           Y coordinate of the upper left corner of the area that the
  467. '           picture is to be painted on. (in pixels)
  468. '   [Width]
  469. '           Width of picture area to paint in pixels.  Note: If this value
  470. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  471. '           instead of the pictures' width in pixels), this procedure will
  472. '           attempt to create bitmaps that require outrageous
  473. '           amounts of memory.
  474. '   [Height]
  475. '           Height of picture area to paint in pixels.  Note: If this
  476. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  477. '           twips instead of the pictures' height in pixels), this
  478. '           procedure will attempt to create bitmaps that require
  479. '           outrageous amounts of memory.
  480. '   [hdcSrc]
  481. '           Device context that contains the source picture
  482. '   [xSrc]
  483. '           X coordinate of the upper left corner of the area in the picture
  484. '           to use as the source. (in pixels)
  485. '   [ySrc]
  486. '           Y coordinate of the upper left corner of the area in the picture
  487. '           to use as the source. (in pixels)
  488. '   [clrMask]
  489. '           Color of pixels to be masked out
  490. '   [hPal]
  491. '           Handle of palette to select into the memory DC's used to create
  492. '           the painting effect.
  493. '           If not provided, a HalfTone palette is used.
  494. '-------------------------------------------------------------------------
  495. Public Sub PaintTransparentDC(ByVal hdcDest As Long, _
  496.                                     ByVal xDest As Long, _
  497.                                     ByVal yDest As Long, _
  498.                                     ByVal Width As Long, _
  499.                                     ByVal Height As Long, _
  500.                                     ByVal hdcSrc As Long, _
  501.                                     ByVal xSrc As Long, _
  502.                                     ByVal ySrc As Long, _
  503.                                     ByVal clrMask As OLE_COLOR, _
  504.                                     Optional ByVal hPal As Long = 0)
  505.     Dim hdcMask As Long        'HDC of the created mask image
  506.     Dim hdcColor As Long       'HDC of the created color image
  507.     Dim hbmMask As Long        'Bitmap handle to the mask image
  508.     Dim hbmColor As Long       'Bitmap handle to the color image
  509.     Dim hbmColorOld As Long
  510.     Dim hbmMaskOld As Long
  511.     Dim hPalOld As Long
  512.     Dim hdcScreen As Long
  513.     Dim hdcScnBuffer As Long         'Buffer to do all work on
  514.     Dim hbmScnBuffer As Long
  515.     Dim hbmScnBufferOld As Long
  516.     Dim hPalBufferOld As Long
  517.     Dim lMaskColor As Long
  518.     
  519.     hdcScreen = GetDC(0&)
  520.     'Validate palette
  521.     If hPal = 0 Then
  522.         hPal = m_hpalHalftone
  523.     End If
  524.     OleTranslateColor clrMask, hPal, lMaskColor
  525.     
  526.     'Create a color bitmap to server as a copy of the destination
  527.     'Do all work on this bitmap and then copy it back over the destination
  528.     'when it's done.
  529.     hbmScnBuffer = CreateCompatibleBitmap(hdcScreen, Width, Height)
  530.     'Create DC for screen buffer
  531.     hdcScnBuffer = CreateCompatibleDC(hdcScreen)
  532.     hbmScnBufferOld = SelectObject(hdcScnBuffer, hbmScnBuffer)
  533.     hPalBufferOld = SelectPalette(hdcScnBuffer, hPal, True)
  534.     RealizePalette hdcScnBuffer
  535.     'Copy the destination to the screen buffer
  536.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcDest, xDest, yDest, vbSrcCopy
  537.     
  538.     'Create a (color) bitmap for the cover (can't use CompatibleBitmap with
  539.     'hdcSrc, because this will create a DIB section if the original bitmap
  540.     'is a DIB section)
  541.     hbmColor = CreateCompatibleBitmap(hdcScreen, Width, Height)
  542.     'Now create a monochrome bitmap for the mask
  543.     hbmMask = CreateBitmap(Width, Height, 1, 1, ByVal 0&)
  544.     'First, blt the source bitmap onto the cover.  We do this first
  545.     'and then use it instead of the source bitmap
  546.     'because the source bitmap may be
  547.     'a DIB section, which behaves differently than a bitmap.
  548.     '(Specifically, copying from a DIB section to a monochrome bitmap
  549.     'does a nearest-color selection rather than painting based on the
  550.     'backcolor and forecolor.
  551.     hdcColor = CreateCompatibleDC(hdcScreen)
  552.     hbmColorOld = SelectObject(hdcColor, hbmColor)
  553.     hPalOld = SelectPalette(hdcColor, hPal, True)
  554.     RealizePalette hdcColor
  555.     'In case hdcSrc contains a monochrome bitmap, we must set the destination
  556.     'foreground/background colors according to those currently set in hdcSrc
  557.     '(because Windows will associate these colors with the two monochrome colors)
  558.     SetBkColor hdcColor, GetBkColor(hdcSrc)
  559.     SetTextColor hdcColor, GetTextColor(hdcSrc)
  560.     BitBlt hdcColor, 0, 0, Width, Height, hdcSrc, xSrc, ySrc, vbSrcCopy
  561.     'Paint the mask.  What we want is white at the transparent color
  562.     'from the source, and black everywhere else.
  563.     hdcMask = CreateCompatibleDC(hdcScreen)
  564.     hbmMaskOld = SelectObject(hdcMask, hbmMask)
  565.  
  566.     'When bitblt'ing from color to monochrome, Windows sets to 1
  567.     'all pixels that match the background color of the source DC.  All
  568.     'other bits are set to 0.
  569.     SetBkColor hdcColor, lMaskColor
  570.     SetTextColor hdcColor, vbWhite
  571.     BitBlt hdcMask, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcCopy
  572.     'Paint the rest of the cover bitmap.
  573.     '
  574.     'What we want here is black at the transparent color, and
  575.     'the original colors everywhere else.  To do this, we first
  576.     'paint the original onto the cover (which we already did), then we
  577.     'AND the inverse of the mask onto that using the DSna ternary raster
  578.     'operation (0x00220326 - see Win32 SDK reference, Appendix, "Raster
  579.     'Operation Codes", "Ternary Raster Operations", or search in MSDN
  580.     'for 00220326).  DSna [reverse polish] means "(not SRC) and DEST".
  581.     '
  582.     'When bitblt'ing from monochrome to color, Windows transforms all white
  583.     'bits (1) to the background color of the destination hdc.  All black (0)
  584.     'bits are transformed to the foreground color.
  585.     SetTextColor hdcColor, vbBlack
  586.     SetBkColor hdcColor, vbWhite
  587.     BitBlt hdcColor, 0, 0, Width, Height, hdcMask, 0, 0, DSna
  588.     'Paint the Mask to the Screen buffer
  589.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcMask, 0, 0, vbSrcAnd
  590.     'Paint the Color to the Screen buffer
  591.     BitBlt hdcScnBuffer, 0, 0, Width, Height, hdcColor, 0, 0, vbSrcPaint
  592.     'Copy the screen buffer to the screen
  593.     BitBlt hdcDest, xDest, yDest, Width, Height, hdcScnBuffer, 0, 0, vbSrcCopy
  594.     'All done!
  595.     DeleteObject SelectObject(hdcColor, hbmColorOld)
  596.     SelectPalette hdcColor, hPalOld, True
  597.     RealizePalette hdcColor
  598.     DeleteDC hdcColor
  599.     DeleteObject SelectObject(hdcScnBuffer, hbmScnBufferOld)
  600.     SelectPalette hdcScnBuffer, hPalBufferOld, True
  601.     RealizePalette hdcScnBuffer
  602.     DeleteDC hdcScnBuffer
  603.     
  604.     DeleteObject SelectObject(hdcMask, hbmMaskOld)
  605.     DeleteDC hdcMask
  606.     ReleaseDC 0&, hdcScreen
  607. End Sub
  608.  
  609. '-------------------------------------------------------------------------
  610. 'Purpose:   Draws a transparent bitmap to a DC.  The pixels of the passed
  611. '           bitmap that match the passed mask color will not be painted
  612. '           to the destination DC
  613. 'In:
  614. '   [hdcDest]
  615. '           Device context to paint the picture on
  616. '   [xDest]
  617. '           X coordinate of the upper left corner of the area that the
  618. '           picture is to be painted on. (in pixels)
  619. '   [yDest]
  620. '           Y coordinate of the upper left corner of the area that the
  621. '           picture is to be painted on. (in pixels)
  622. '   [Width]
  623. '           Width of picture area to paint in pixels.  Note: If this value
  624. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  625. '           instead of the pictures' width in pixels), this procedure will
  626. '           attempt to create bitmaps that require outrageous
  627. '           amounts of memory.
  628. '   [Height]
  629. '           Height of picture area to paint in pixels.  Note: If this
  630. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  631. '           twips instead of the pictures' height in pixels), this
  632. '           procedure will attempt to create bitmaps that require
  633. '           outrageous amounts of memory.
  634. '   [picSource]
  635. '           Standard Picture object to be used as the image source
  636. '   [xSrc]
  637. '           X coordinate of the upper left corner of the area in the picture
  638. '           to use as the source. (in pixels)
  639. '           Ignored if picSource is an Icon.
  640. '   [ySrc]
  641. '           Y coordinate of the upper left corner of the area in the picture
  642. '           to use as the source. (in pixels)
  643. '           Ignored if picSource is an Icon.
  644. '   [clrMask]
  645. '           Color of pixels to be masked out
  646. '   [hPal]
  647. '           Handle of palette to select into the memory DC's used to create
  648. '           the painting effect.
  649. '           If not provided, a HalfTone palette is used.
  650. '-------------------------------------------------------------------------
  651. Public Sub PaintTransparentStdPic(ByVal hdcDest As Long, _
  652.                                     ByVal xDest As Long, _
  653.                                     ByVal yDest As Long, _
  654.                                     ByVal Width As Long, _
  655.                                     ByVal Height As Long, _
  656.                                     ByVal picSource As Picture, _
  657.                                     ByVal xSrc As Long, _
  658.                                     ByVal ySrc As Long, _
  659.                                     ByVal clrMask As OLE_COLOR, _
  660.                                     Optional ByVal hPal As Long = 0)
  661.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  662.     Dim hbmMemSrcOld As Long
  663.     Dim hbmMemSrc As Long
  664.     Dim udtRect As RECT
  665.     Dim hbrMask As Long
  666.     Dim lMaskColor As Long
  667.     Dim hdcScreen As Long
  668.     Dim hPalOld As Long
  669.     'Verify that the passed picture is a Bitmap
  670.     If picSource Is Nothing Then GoTo PaintTransparentStdPic_InvalidParam
  671.     
  672.     Select Case picSource.Type
  673.         Case vbPicTypeBitmap
  674.             hdcScreen = GetDC(0&)
  675.             'Validate palette
  676.             If hPal = 0 Then
  677.                 hPal = m_hpalHalftone
  678.             End If
  679.             'Select passed picture into an HDC
  680.             hdcSrc = CreateCompatibleDC(hdcScreen)
  681.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  682.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  683.             RealizePalette hdcSrc
  684.             'Draw the bitmap
  685.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, clrMask, hPal
  686.             
  687.             SelectObject hdcSrc, hbmMemSrcOld
  688.             SelectPalette hdcSrc, hPalOld, True
  689.             RealizePalette hdcSrc
  690.             DeleteDC hdcSrc
  691.             ReleaseDC 0&, hdcScreen
  692.         Case vbPicTypeIcon
  693.             'Create a bitmap and select it into an DC
  694.             hdcScreen = GetDC(0&)
  695.             'Validate palette
  696.             If hPal = 0 Then
  697.                 hPal = m_hpalHalftone
  698.             End If
  699.             hdcSrc = CreateCompatibleDC(hdcScreen)
  700.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  701.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  702.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  703.             RealizePalette hdcSrc
  704.             'Draw Icon onto DC
  705.             udtRect.Bottom = Height
  706.             udtRect.Right = Width
  707.             OleTranslateColor clrMask, 0&, lMaskColor
  708.             hbrMask = CreateSolidBrush(lMaskColor)
  709.             FillRect hdcSrc, udtRect, hbrMask
  710.             DeleteObject hbrMask
  711.             DrawIcon hdcSrc, 0, 0, picSource.handle
  712.             'Draw Transparent image
  713.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0, 0, lMaskColor, hPal
  714.             'Clean up
  715.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  716.             SelectPalette hdcSrc, hPalOld, True
  717.             RealizePalette hdcSrc
  718.             DeleteDC hdcSrc
  719.             ReleaseDC 0&, hdcScreen
  720.         Case Else
  721.             GoTo PaintTransparentStdPic_InvalidParam
  722.     End Select
  723.     Exit Sub
  724. PaintTransparentStdPic_InvalidParam:
  725.     Err.Raise giINVALID_PICTURE
  726.     Exit Sub
  727. End Sub
  728.  
  729. '-------------------------------------------------------------------------
  730. 'Purpose:   Draws a standard picture object to a DC
  731. 'In:
  732. '   [hdcDest]
  733. '           Handle of the device context to paint the picture on
  734. '   [xDest]
  735. '           X coordinate of the upper left corner of the area that the
  736. '           picture is to be painted on. (in pixels)
  737. '   [yDest]
  738. '           Y coordinate of the upper left corner of the area that the
  739. '           picture is to be painted on. (in pixels)
  740. '   [Width]
  741. '           Width of picture area to paint in pixels.  Note: If this value
  742. '           is outrageous (i.e.: you passed a forms ScaleWidth in twips
  743. '           instead of the pictures' width in pixels), this procedure will
  744. '           attempt to create bitmaps that require outrageous
  745. '           amounts of memory.
  746. '   [Height]
  747. '           Height of picture area to paint in pixels.  Note: If this
  748. '           value is outrageous (i.e.: you passed a forms ScaleHeight in
  749. '           twips instead of the pictures' height in pixels), this
  750. '           procedure will attempt to create bitmaps that require
  751. '           outrageous amounts of memory.
  752. '   [picSource]
  753. '           Standard Picture object to be used as the image source
  754. '   [xSrc]
  755. '           X coordinate of the upper left corner of the area in the picture
  756. '           to use as the source. (in pixels)
  757. '           Ignored if picSource is an Icon.
  758. '   [ySrc]
  759. '           Y coordinate of the upper left corner of the area in the picture
  760. '           to use as the source. (in pixels)
  761. '           Ignored if picSource is an Icon.
  762. '   [hPal]
  763. '           Handle of palette to select into the memory DC's used to create
  764. '           the painting effect.
  765. '           If not provided, a HalfTone palette is used.
  766. '-------------------------------------------------------------------------
  767. Public Sub PaintNormalStdPic(ByVal hdcDest As Long, _
  768.                                     ByVal xDest As Long, _
  769.                                     ByVal yDest As Long, _
  770.                                     ByVal Width As Long, _
  771.                                     ByVal Height As Long, _
  772.                                     ByVal picSource As Picture, _
  773.                                     ByVal xSrc As Long, _
  774.                                     ByVal ySrc As Long, _
  775.                                     Optional ByVal hPal As Long = 0)
  776.     Dim hdcTemp As Long
  777.     Dim hPalOld As Long
  778.     Dim hbmMemSrcOld As Long
  779.     Dim hdcScreen As Long
  780.     Dim hbmMemSrc As Long
  781.     'Validate that a bitmap was passed in
  782.     If picSource Is Nothing Then GoTo PaintNormalStdPic_InvalidParam
  783.     Select Case picSource.Type
  784.         Case vbPicTypeBitmap
  785.             If hPal = 0 Then
  786.                 hPal = m_hpalHalftone
  787.             End If
  788.             hdcScreen = GetDC(0&)
  789.             'Create a DC to select bitmap into
  790.             hdcTemp = CreateCompatibleDC(hdcScreen)
  791.             hPalOld = SelectPalette(hdcTemp, hPal, True)
  792.             RealizePalette hdcTemp
  793.             'Select bitmap into DC
  794.             hbmMemSrcOld = SelectObject(hdcTemp, picSource.handle)
  795.             'Copy to destination DC
  796.             BitBlt hdcDest, xDest, yDest, Width, Height, hdcTemp, xSrc, ySrc, vbSrcCopy
  797.             'Cleanup
  798.             SelectObject hdcTemp, hbmMemSrcOld
  799.             SelectPalette hdcTemp, hPalOld, True
  800.             RealizePalette hdcTemp
  801.             DeleteDC hdcTemp
  802.             ReleaseDC 0&, hdcScreen
  803.         Case vbPicTypeIcon
  804.             'Create a bitmap and select it into an DC
  805.             'Draw Icon onto DC
  806.             DrawIconEx hdcDest, xDest, yDest, picSource.handle, Width, Height, 0&, 0&, DI_NORMAL
  807.         Case Else
  808.             GoTo PaintNormalStdPic_InvalidParam
  809.     End Select
  810.     Exit Sub
  811. PaintNormalStdPic_InvalidParam:
  812.     Err.Raise giINVALID_PICTURE
  813. End Sub
  814.  
  815. Private Sub Class_Initialize()
  816.     Dim hdcScreen As Long
  817.     'Create halftone palette
  818.     hdcScreen = GetDC(0&)
  819.     m_hpalHalftone = CreateHalftonePalette(hdcScreen)
  820.     ReleaseDC 0&, hdcScreen
  821. End Sub
  822.  
  823. Private Sub Class_Terminate()
  824.     DeleteObject m_hpalHalftone
  825. End Sub
  826.  
  827. Public Sub PaintTransCornerDC(ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long)
  828.    '
  829.    ' 32-Bit Transparent BitBlt Function
  830.    ' Written by Geoff Glaze 2/13/98
  831.    '
  832.    ' Purpose:
  833.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  834.    '
  835.    ' Parameters ************************************************************
  836.    '   hDestDC:     Destination device context
  837.    '   x, y:        Upper-left destination coordinates (pixels)
  838.    '   nWidth:      Width of destination
  839.    '   nHeight:     Height of destination
  840.    '   hSrcDC:      Source device context
  841.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  842.    ' ***********************************************************************
  843.    
  844.    Dim iBackColor As Long
  845.     
  846.    iBackColor = GetPixel(hSrcDC, 0, 0)
  847.    If iBackColor = CLR_INVALID Then
  848.         'invalid color (specified point is outside of the clipping region)
  849.         'use default grey (standard bitmap back color)
  850.         iBackColor = &HC0C0C0
  851.     End If
  852.    
  853.    PaintTransparentDC hDestDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, iBackColor
  854.    
  855. End Sub
  856.  
  857. Public Sub PaintDisabledCornerDC(ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long)
  858.    '
  859.    ' 32-Bit Transparent BitBlt Function
  860.    ' Written by Geoff Glaze 2/13/98
  861.    '
  862.    ' Purpose:
  863.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  864.    '
  865.    ' Parameters ************************************************************
  866.    '   hDestDC:     Destination device context
  867.    '   x, y:        Upper-left destination coordinates (pixels)
  868.    '   nWidth:      Width of destination
  869.    '   nHeight:     Height of destination
  870.    '   hSrcDC:      Source device context
  871.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  872.    ' ***********************************************************************
  873.    
  874.    Dim iBackColor As Long
  875.     
  876.    iBackColor = GetPixel(hSrcDC, 0, 0)
  877.    If iBackColor = CLR_INVALID Then
  878.         'invalid color (specified point is outside of the clipping region)
  879.         'use default grey (standard bitmap back color)
  880.         iBackColor = &HC0C0C0
  881.     End If
  882.    
  883.    PaintDisabledDC hDestDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, iBackColor
  884.    
  885. End Sub
  886.  
  887. Public Sub PaintTransCornerStdPic(ByVal hdcDest As Long, _
  888.                                     ByVal xDest As Long, _
  889.                                     ByVal yDest As Long, _
  890.                                     ByVal Width As Long, _
  891.                                     ByVal Height As Long, _
  892.                                     ByVal picSource As Picture, _
  893.                                     ByVal xSrc As Long, _
  894.                                     ByVal ySrc As Long, _
  895.                                     Optional ByVal hPal As Long = 0)
  896.    '
  897.    ' 32-Bit Transparent BitBlt Function
  898.    ' Written by Geoff Glaze 2/13/98
  899.    '
  900.    ' Purpose:
  901.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  902.    '
  903.    ' Parameters ************************************************************
  904.    '   hDestDC:     Destination device context
  905.    '   x, y:        Upper-left destination coordinates (pixels)
  906.    '   nWidth:      Width of destination
  907.    '   nHeight:     Height of destination
  908.    '   hSrcDC:      Source device context
  909.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  910.    ' ***********************************************************************
  911.    
  912.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  913.     Dim hbmMemSrcOld As Long
  914.     Dim hbmMemSrc As Long
  915.     Dim udtRect As RECT
  916.     Dim hbrMask As Long
  917.     Dim lMaskColor As Long
  918.     Dim hdcScreen As Long
  919.     Dim hPalOld As Long
  920.     'Verify that the passed picture is a Bitmap
  921.     If picSource Is Nothing Then GoTo PaintTransCornerStdPic_InvalidParam
  922.     
  923.     Select Case picSource.Type
  924.         Case vbPicTypeBitmap
  925.             hdcScreen = GetDC(0&)
  926.             'Validate palette
  927.             If hPal = 0 Then
  928.                 hPal = m_hpalHalftone
  929.             End If
  930.             'Select passed picture into an HDC
  931.             hdcSrc = CreateCompatibleDC(hdcScreen)
  932.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  933.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  934.             RealizePalette hdcSrc
  935.             
  936.             'get back color
  937.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  938.             If lMaskColor = CLR_INVALID Then
  939.                  'invalid color (specified point is outside of the clipping region)
  940.                  'use default grey (standard bitmap back color)
  941.                  lMaskColor = &HC0C0C0
  942.             End If
  943.             
  944.             'Draw the bitmap
  945.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, lMaskColor, hPal
  946.             
  947.             SelectObject hdcSrc, hbmMemSrcOld
  948.             SelectPalette hdcSrc, hPalOld, True
  949.             RealizePalette hdcSrc
  950.             DeleteDC hdcSrc
  951.             ReleaseDC 0&, hdcScreen
  952.         Case vbPicTypeIcon
  953.             'Create a bitmap and select it into an DC
  954.             hdcScreen = GetDC(0&)
  955.             'Validate palette
  956.             If hPal = 0 Then
  957.                 hPal = m_hpalHalftone
  958.             End If
  959.             hdcSrc = CreateCompatibleDC(hdcScreen)
  960.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  961.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  962.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  963.             RealizePalette hdcSrc
  964.             'Draw Icon onto DC
  965.             udtRect.Bottom = Height
  966.             udtRect.Right = Width
  967.             
  968.             'get back color
  969.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  970.             If lMaskColor = CLR_INVALID Then
  971.                  'invalid color (specified point is outside of the clipping region)
  972.                  'use default grey (standard bitmap back color)
  973.                  lMaskColor = &HC0C0C0
  974.             End If
  975.             
  976. '            OleTranslateColor clrMask, 0&, lMaskColor
  977.             hbrMask = CreateSolidBrush(lMaskColor)
  978.             FillRect hdcSrc, udtRect, hbrMask
  979.             DeleteObject hbrMask
  980.             DrawIcon hdcSrc, 0, 0, picSource.handle
  981.             'Draw Transparent image
  982.             PaintTransparentDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0, 0, lMaskColor, hPal
  983.             'Clean up
  984.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  985.             SelectPalette hdcSrc, hPalOld, True
  986.             RealizePalette hdcSrc
  987.             DeleteDC hdcSrc
  988.             ReleaseDC 0&, hdcScreen
  989.         Case Else
  990.             GoTo PaintTransCornerStdPic_InvalidParam
  991.     End Select
  992.     Exit Sub
  993.  
  994. PaintTransCornerStdPic_InvalidParam:
  995.     Err.Raise giINVALID_PICTURE
  996.     Exit Sub
  997.    
  998. End Sub
  999.  
  1000. Public Sub PaintDisabledCornerStdPic(ByVal hdcDest As Long, _
  1001.                                     ByVal xDest As Long, _
  1002.                                     ByVal yDest As Long, _
  1003.                                     ByVal Width As Long, _
  1004.                                     ByVal Height As Long, _
  1005.                                     ByVal picSource As Picture, _
  1006.                                     ByVal xSrc As Long, _
  1007.                                     ByVal ySrc As Long, _
  1008.                                     Optional ByVal hPal As Long = 0)
  1009.    '
  1010.    ' 32-Bit Transparent BitBlt Function
  1011.    ' Written by Geoff Glaze 2/13/98
  1012.    '
  1013.    ' Purpose:
  1014.    '    Creates a transparent bitmap using lower left pixel of source bitmap
  1015.    '
  1016.    ' Parameters ************************************************************
  1017.    '   hDestDC:     Destination device context
  1018.    '   x, y:        Upper-left destination coordinates (pixels)
  1019.    '   nWidth:      Width of destination
  1020.    '   nHeight:     Height of destination
  1021.    '   hSrcDC:      Source device context
  1022.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  1023.    ' ***********************************************************************
  1024.    
  1025.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  1026.     Dim hbmMemSrcOld As Long
  1027.     Dim hbmMemSrc As Long
  1028.     Dim udtRect As RECT
  1029.     Dim hbrMask As Long
  1030.     Dim lMaskColor As Long
  1031.     Dim hdcScreen As Long
  1032.     Dim hPalOld As Long
  1033.     'Verify that the passed picture is a Bitmap
  1034.     If picSource Is Nothing Then GoTo PaintDisabledCornerStdPic_InvalidParam
  1035.     
  1036.     Select Case picSource.Type
  1037.         Case vbPicTypeBitmap
  1038.             hdcScreen = GetDC(0&)
  1039.             'Validate palette
  1040.             If hPal = 0 Then
  1041.                 hPal = m_hpalHalftone
  1042.             End If
  1043.             'Select passed picture into an HDC
  1044.             hdcSrc = CreateCompatibleDC(hdcScreen)
  1045.             hbmMemSrcOld = SelectObject(hdcSrc, picSource.handle)
  1046.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  1047.             RealizePalette hdcSrc
  1048.             
  1049.             'get back color
  1050.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  1051.             If lMaskColor = CLR_INVALID Then
  1052.                  'invalid color (specified point is outside of the clipping region)
  1053.                  'use default grey (standard bitmap back color)
  1054.                  lMaskColor = &HC0C0C0
  1055.             End If
  1056.             
  1057.             'Draw the bitmap
  1058.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, xSrc, ySrc, lMaskColor, , , hPal
  1059.             
  1060.             SelectObject hdcSrc, hbmMemSrcOld
  1061.             SelectPalette hdcSrc, hPalOld, True
  1062.             RealizePalette hdcSrc
  1063.             DeleteDC hdcSrc
  1064.             ReleaseDC 0&, hdcScreen
  1065.         Case vbPicTypeIcon
  1066.             'Create a bitmap and select it into an DC
  1067.             hdcScreen = GetDC(0&)
  1068.             'Validate palette
  1069.             If hPal = 0 Then
  1070.                 hPal = m_hpalHalftone
  1071.             End If
  1072.             hdcSrc = CreateCompatibleDC(hdcScreen)
  1073.             hbmMemSrc = CreateCompatibleBitmap(hdcScreen, Width, Height)
  1074.             hbmMemSrcOld = SelectObject(hdcSrc, hbmMemSrc)
  1075.             hPalOld = SelectPalette(hdcSrc, hPal, True)
  1076.             RealizePalette hdcSrc
  1077.             'Draw Icon onto DC
  1078.             udtRect.Bottom = Height
  1079.             udtRect.Right = Width
  1080. '            OleTranslateColor clrMask, 0&, lMaskColor
  1081.             
  1082.             'get back color
  1083.             lMaskColor = GetPixel(hdcSrc, 0, 0)
  1084.             If lMaskColor = CLR_INVALID Then
  1085.                  'invalid color (specified point is outside of the clipping region)
  1086.                  'use default grey (standard bitmap back color)
  1087.                  lMaskColor = &HC0C0C0
  1088.             End If
  1089.  
  1090.             hbrMask = CreateSolidBrush(lMaskColor)
  1091.             FillRect hdcSrc, udtRect, hbrMask
  1092.             DeleteObject hbrMask
  1093.             DrawIcon hdcSrc, 0, 0, picSource.handle
  1094.             'Draw Transparent image
  1095.             PaintDisabledDC hdcDest, xDest, yDest, Width, Height, hdcSrc, 0, 0, lMaskColor, , , hPal
  1096.             'Clean up
  1097.             DeleteObject SelectObject(hdcSrc, hbmMemSrcOld)
  1098.             SelectPalette hdcSrc, hPalOld, True
  1099.             RealizePalette hdcSrc
  1100.             DeleteDC hdcSrc
  1101.             ReleaseDC 0&, hdcScreen
  1102.         Case Else
  1103.             GoTo PaintDisabledCornerStdPic_InvalidParam
  1104.     End Select
  1105.     Exit Sub
  1106.  
  1107. PaintDisabledCornerStdPic_InvalidParam:
  1108.     Err.Raise giINVALID_PICTURE
  1109.     Exit Sub
  1110.    
  1111. End Sub
  1112.  
  1113. Public Sub PaintGreyScaleCornerStdPic(ByVal hdcDest As Long, _
  1114.                                     ByVal xDest As Long, _
  1115.                                     ByVal yDest As Long, _
  1116.                                     ByVal Width As Long, _
  1117.                                     ByVal Height As Long, _
  1118.                                     ByVal picSource As Picture, _
  1119.                                     ByVal xSrc As Long, _
  1120.                                     ByVal ySrc As Long, _
  1121.                                     Optional ByVal hPal As Long = 0)
  1122.    '
  1123.    ' 32-Bit GreyScale BitBlt Function
  1124.    ' Written by Geoff Glaze 2/13/98
  1125.    '
  1126.    ' Purpose:
  1127.    '    Creates a greyscale version of a bitmap
  1128.    '
  1129.    ' Parameters ************************************************************
  1130.    '   hDestDC:     Destination device context
  1131.    '   x, y:        Upper-left destination coordinates (pixels)
  1132.    '   nWidth:      Width of destination
  1133.    '   nHeight:     Height of destination
  1134.    '   hSrcDC:      Source device context
  1135.    '   xSrc, ySrc:  Upper-left source coordinates (pixels)
  1136.    ' ***********************************************************************
  1137.    
  1138.     Dim hdcSrc As Long         'HDC that the source bitmap is selected into
  1139.     Dim hbmMemSrcOld As Long
  1140.     Dim hbmMemSrc As Long
  1141.     Dim udtRect As RECT
  1142.     Dim hbrMask As Long
  1143.     Dim lMaskColor As Long
  1144.     Dim hdcScreen As Long
  1145.     Dim hPalOld As Long
  1146.     Dim hBrush As Long
  1147.     'Verify that the passed picture is a Bitmap
  1148.     If picSource Is Nothing Then GoTo PaintGreyScaleCornerStdPic_InvalidParam
  1149.     
  1150.     hBrush = CreateSolidBrush(RGB(100, 100, 100))
  1151.     Select Case picSource.Type
  1152.         Case vbPicTypeBitmap
  1153.             Call DrawState(hdcDest, hBrush, 0&, picSource, 0&, xDest, yDest, Width, Height, DST_BITMAP Or DSS_UNION)
  1154.         Case vbPicTypeIcon
  1155.             Call DrawState(hdcDest, hBrush, 0&, picSource, 0&, xDest, yDest, Width, Height, DST_ICON Or DSS_UNION)
  1156.         Case Else
  1157.             GoTo PaintGreyScaleCornerStdPic_InvalidParam
  1158.     End Select
  1159.     Exit Sub
  1160.  
  1161. PaintGreyScaleCornerStdPic_InvalidParam:
  1162.     Err.Raise giINVALID_PICTURE
  1163.     Exit Sub
  1164.    
  1165. End Sub
  1166.  
  1167. Public Function GetRedAmount(ByVal iColor As Long) As Long
  1168.     GetRedAmount = iColor Mod 256
  1169. End Function
  1170.  
  1171. Public Function GetGreenAmount(ByVal iColor As Long) As Long
  1172.     GetGreenAmount = (iColor \ 256) Mod 256
  1173. End Function
  1174.  
  1175. Public Function GetBlueAmount(ByVal iColor As Long) As Long
  1176.     GetBlueAmount = (iColor \ 256 ^ 2) Mod 256
  1177. End Function
  1178.  
  1179. Public Function AverageColors(ByVal iColor1 As Long, iColor2 As Long) As Long
  1180.     Dim xRed As Long
  1181.     Dim xGreen As Long
  1182.     Dim xBlue As Long
  1183.     xRed = (GetRedAmount(iColor1) + GetRedAmount(iColor2)) \ 2
  1184.     xGreen = (GetGreenAmount(iColor1) + GetGreenAmount(iColor2)) \ 2
  1185.     xBlue = (GetBlueAmount(iColor1) + GetBlueAmount(iColor2)) \ 2
  1186.     AverageColors = RGB(xRed, xGreen, xBlue)
  1187. End Function
  1188.  
  1189.  
  1190.